package com.siyuanren.gcocp.service.impl;

import com.siyuanren.gcocp.dto.UserDTO;
import com.siyuanren.gcocp.entity.WxUser;
import com.siyuanren.gcocp.entity.WxUserCourseExample;
import com.siyuanren.gcocp.mapper.MyWxUserMapper;
import com.siyuanren.gcocp.mapper.base.WxUserCourseMapper;
import com.siyuanren.gcocp.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by   anxing
 * Project_name gcocp-parent
 * Path         com.siyuanren.gcocp.service.impl
 * Date         2018/6/12
 * Time         13:37
 * Description
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    MyWxUserMapper userMapper;
    @Autowired
    WxUserCourseMapper userCourseMapper;

    @Override
    public UserDTO getUserInfo(Integer userId) {
        WxUser wxUser = userMapper.selectByPrimaryKey(userId);
        UserDTO userDTO = new UserDTO();
        BeanUtils.copyProperties(wxUser, userDTO);

        // 课程数量
        WxUserCourseExample example = new WxUserCourseExample();
        example.or().andUserIdEqualTo(userId).andAvailableEqualTo(true);
        long count = userCourseMapper.countByExample(example);
        userDTO.setCourseCount((int) count);

        return userDTO;
    }
}
